#ifndef __FACTORY_H__
#define __FACTORY_H__

#include "head.h"
#include "work_que.h"
#include "trans.h"


#define USER_NAME_LENGTH 64
#define USER_HOME_PATH_LENGTH 128
#define MAX_USER 2//最大同时处理用户数


typedef struct usNod
{
    int fd;
    char userName[USER_NAME_LENGTH];
    char homePath[USER_HOME_PATH_LENGTH];
    struct usNod *next;
} userNode_t, *puserNode;

typedef struct 
{
    int epfd;            //epoll描述符
    int userNum;         //现有用户数量
    puserNode userlink;  //用户链表
    pthread_mutex_t mutex;
} users_t, *pusers;

typedef struct{
    taskQue_t que;//传输任务队列
    pthread_cond_t cond;//控制同步

    int socketFd;//最外层的socketFd，用来建立新的连接
    int transFd;//传输端口连接

    int maxUsers; //最大用户数
    users_t users;//用户
    
    pthread_t *pthid; //存储传输子线程ID的起始地址
    int tpThreadNum; //传输线程数目
    
    int startFlag;//工厂是否启动


}factory_t,*pFactory_t;




int user_login(pFactory_t pfac, int newFd,puserNode *);


typedef struct{
    int dataLen;//存储的是 buf上到底运了多少数据
    char buf[1000];//存储要发送的数据
}train_t;

int factory_init(pFactory_t,int,int);//factory_t 地址 子线程个数 任务队列容量
int factory_launch(pFactory_t);
int tcp_init(int*,char*,char*);
int trans_file(ptaskNode_t);
int recv_file(ptaskNode_t ptask);


#define CONFIG_FILENAME "./conf/server.conf"

int read_config(const char *filename,char args[][20],int argNum);



enum command_e
{
    CMD_PWD = 0,//这个零号后期给他做成退出指令
    CMD_LS,
    CMD_CD,
    CMD_PUTS,
    CMD_GETS,

    CMD_TYPES
};
#define CMD_LENGTH 6

typedef struct
{
    char command[CMD_LENGTH];
    void (*func)(puserNode puser,pFactory_t pfac);
} command_t;


void cmd_ls(puserNode puser,pFactory_t pfac);

void cmd_cd(puserNode puser,pFactory_t pfac);

void cmd_puts(puserNode puser,pFactory_t pfac);

void cmd_gets(puserNode puser,pFactory_t pfac);


#endif

